// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

import config from "./utils/config";
//模拟类
//定义属性
const socketManage ={
    _socket:io(config.url),
    pokers:[],
    roomId:0,
    desktop:[],
}
//定义方法
socketManage.init=function () {
    socketManage._socket=io(config.url);
}
socketManage.request=function (msgType,id,data) {
    socketManage._socket.emit(msgType,data);
}
socketManage.on=function (msgType,cb) {
    socketManage._socket.on(msgType,(msg)=>{
        cb(msg);
    });
}
socketManage._socket.on("startGame",(data)=>{
    socketManage.roomId==data;
    console.log("receive roomId:"+data)
})
socketManage._socket.on("dispatchPoker",(data)=>{
    socketManage.desktop=data;
    console.log("receive pokers data");
})
//返回使用
export default  socketManage;
